<template>
  <div class="data-list">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="rbNoteId" label="笔记ID" width="150"></el-table-column>
      <el-table-column prop="clientId" label="客户ID" width="150"></el-table-column>
      <el-table-column prop="clientName" label="客户名" width="200"></el-table-column>
      <el-table-column prop="noteContent" label="笔记内容" width="300"></el-table-column>
      <el-table-column prop="commentContent" label="评论内容" width="300"></el-table-column>
      <el-table-column prop="noteKeyWord" label="笔记关键词" width="200"></el-table-column>
      <el-table-column prop="commentKeyWord" label="评论关键词" width="200"></el-table-column>
      <el-table-column prop="clientActivityId" label="活动ID" width="150"></el-table-column>
      <el-table-column prop="activityTime" label="活动时间" width="200"></el-table-column>
      <el-table-column label="操作" width="280" align="center">
        <template slot-scope="scope">
          <el-button @click="updateKeyword(scope.row)" type="primary" size="mini">修改关键词</el-button>
          <el-button @click="intoMessageArray(scope.row)" type="info" size="mini">进入消息数组</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from 'axios';
import ElementUI from 'element-plus';

export default {
  data() {
    return {
      tableData: []
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      axios.get('/rb/data/getUneditedData')
        .then(response => {
          this.tableData = response.data;
        })
        .catch(error => {
          console.error('There was an error fetching the data!', error);
        });
    },
    updateKeyword(row) {
      const { noteId, clientActivityId, noteKeyWord } = row;
      axios.post('http://localhost:8080/rb/data/updateKeyword', null, {
        params: {
          keyword: noteKeyWord,
          activityId: clientActivityId,
          noteId: noteId
        }
      }).then(response => {
        // 处理成功响应
        console.log('Keyword updated successfully:', response);
      }).catch(error => {
        // 处理错误
        console.error('Error updating keyword:', error);
      });
    },
    intoMessageArray(row) {
      const { clientId, activityTime } = row;
      axios.post('http://localhost:8080/rb/data/intoMessageArray', null, {
        params: {
          clientId: clientId,
          activityTime: activityTime
        }
      }).then(response => {
        // 处理成功响应
        console.log('Entered message array successfully:', response);
      }).catch(error => {
        // 处理错误
        console.error('Error entering message array:', error);
      });
    }
  }
};
</script>

<style scoped>
.data-list {
  margin: 50px auto;
  max-width: 1200px;
}
</style>